<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>图书馆座位预约系统 - 座位选择</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        body {
            background: #f0f2f5;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 60px 0 80px;
        }

        .container {
            max-width: 1200px;
            margin: 30px auto;
            padding: 40px;
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        h2 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 40px;
            font-size: 28px;
        }

        .seat-grid {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
            gap: 15px;
            margin-bottom: 30px;
        }

        .seat {
            padding: 25px 10px;
            text-align: center;
            cursor: pointer;
            border-radius: 8px;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            border: 2px solid transparent;
        }

        .available {
            background: #3498db;
            color: white;
            box-shadow: 0 2px 4px rgba(52, 152, 219, 0.3);
        }

        .available:hover {
            transform: translateY(-3px);
            box-shadow: 0 4px 8px rgba(52, 152, 219, 0.4);
        }

        .booked {
            background: #ecf0f1;
            color: #95a5a6;
            cursor: not-allowed;
        }

        .seat::before {
            content: "💺";
            display: block;
            font-size: 24px;
            margin-bottom: 8px;
        }

        .booked::before {
            content: "⛔";
        }

        #selected-seat-message {
            text-align: center;
            font-size: 1.3em;
            color: #2c3e50;
            margin: 25px 0;
            padding: 15px;
            background: #e8f4ff;
            border-radius: 8px;
            display: none;
        }

        #reservation-form {
            max-width: 500px;
            margin: 30px auto;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .form-active {
            opacity: 1 !important;
        }

        .form-group {
            margin-bottom: 25px;
        }

        label {
            display: block;
            margin-bottom: 10px;
            color: #34495e;
            font-weight: 500;
        }

        input[type="datetime-local"] {
            width: 100%;
            padding: 12px;
            border: 2px solid #e0e0e0;
            border-radius: 6px;
            font-size: 16px;
            transition: border-color 0.3s ease;
        }

        input[type="datetime-local"]:focus {
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }

        button[type="submit"] {
            background: #3498db;
            color: white;
            padding: 14px 30px;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            width: 100%;
        }

        button[type="submit"]:hover {
            background: #2980b9;
            transform: translateY(-1px);
            box-shadow: 0 2px 6px rgba(41, 128, 185, 0.4);
        }

        nav {
            background: #2c3e50;
            padding: 15px 0;
            position: fixed;
            bottom: 0;
            width: 100%;
        }

        nav ul {
            list-style: none;
            padding: 0;
            margin: 0;
            display: flex;
            justify-content: center;
            gap: 30px;
        }

        nav a {
            color: white;
            font-size: 16px;
            transition: color 0.3s ease;
        }

        nav a:hover {
            color: #3498db;
            text-decoration: none;
        }

        @media (max-width: 768px) {
            .seat-grid {
                grid-template-columns: repeat(4, 1fr);
            }

            .container {
                padding: 25px;
                margin: 20px;
            }

            nav ul {
                gap: 15px;
                flex-wrap: wrap;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <h2>📚 座位选择</h2>
    <div class="seat-grid">
        <div th:each="seat : ${seats}"
             th:class="${seat.status == 0} ? 'seat available' : 'seat booked'"
             th:text="${seat.seatNumber}"
             th:onclick="${seat.status == 0} ? 'selectSeat(' + ${seat.id} + ')' : ''">
        </div>
    </div>
    <p id="selected-seat-message"></p>
    <form id="reservation-form" th:action="@{/reservations/create}" method="post">
        <input type="hidden" id="selected-seat-id" name="seatId">
        <div class="form-group">
            <label for="start-time">⏰ 开始时间</label>
            <input type="datetime-local" id="start-time" name="startTime" required>
        </div>
        <div class="form-group">
            <label for="end-time">⏳ 结束时间</label>
            <input type="datetime-local" id="end-time" name="endTime" required>
        </div>
        <button type="submit">✅ 确认预约</button>
    </form>
    <p style="text-align:center; margin-top:25px;">
        <a href="/history" style="color:#3498db;">📖 查看预约历史 →</a>
    </p>
</div>
<nav>
    <ul>
        <li><a href="/login">🔑 登录</a></li>
        <li><a href="/register">📝 注册</a></li>
        <li><a href="/announcements">📢 公告</a></li>
    </ul>
</nav>
<script>
    function selectSeat(seatId) {
        document.getElementById('selected-seat-id').value = seatId;
        const message = document.getElementById('selected-seat-message');
        message.innerText = `✅ 已选择座位号：${seatId}`;
        message.style.display = 'block';

        const form = document.getElementById('reservation-form');
        form.classList.add('form-active');
        form.scrollIntoView({ behavior: 'smooth' });
    }
</script>
</body>
</html>